import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';

import '../../api/DeviceApi.dart';
import '../../commponets/ItemView.dart';
import '../../home/AppLocale.dart';
import '../../tools/widgets/my_app_bar.dart';
import 'model/Device.dart';


class DeviceStoragePage extends StatefulWidget {
  const DeviceStoragePage({
    super.key,
    this.deviceId,
    this.device,
  });

  final int? deviceId;
  final Device? device;

  @override
  State<DeviceStoragePage> createState() => _DeviceStoragePageState();
}

class _DeviceStoragePageState extends State<DeviceStoragePage> {
  final DeviceApi _deviceApi = DeviceApi();
  late int _deviceId;
  Device? _device;

  @override
  void initState() {
    super.initState();

    _deviceId = widget.deviceId!;
    _device = widget.device!;
    // _fetchData();
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: AppLocale.text('d_bendicunchu'),
        backgroundColor: Colors.transparent,
        dropdownWidth: 140,
        dropdownBackgroundColor: Colors.white,
        dropdownBorderRadius: 20,
      ),

      body: Container(
          child: Column(
            children: [

              const SizedBox(height: 20,),

              ItemView(
                width: 400,
                height: 50,
                leftPadding: 10,
                rightPadding: 20,
                leftWidget: Row(
                  children: [
                    const SizedBox(width: 10),
                    Text(
                      AppLocale.text('d_sdkongjian'),
                      style: TextStyle(
                          fontSize: 15.0,
                          color: Colors.black
                      ),
                    ),
                  ],
                ),
                rightWidget: Row(
                  children: [
                    Text(
                      _device?.storageRemaining == null && _device?.storageTotal == null
                          ? AppLocale.text('d_kong')
                          : '${(_device?.storageRemaining ?? 0.0)}/${(_device?.storageTotal ?? 0.0)}G' + AppLocale.text('d_shengyukongjian'),
                      style: TextStyle(
                          fontSize: 14.0,
                          color: Colors.black54),
                    ),
                  ],
                ),
                borderRadius: 8,
                onTap: () {

                },
              ),


              ItemView(
                width: 400,
                height: 50,
                leftPadding: 10,
                rightPadding: 20,
                leftWidget: Row(
                  children: [
                    const SizedBox(width: 10),
                    Text(
                      AppLocale.text('d_geshihua'),
                      style: TextStyle(
                          fontSize: 15.0,
                          color: Colors.black
                      ),
                    ),
                  ],
                ),

                borderRadius: 8,
                onTap: () {
                  BrnDialogManager.showConfirmDialog(context,
                      title: AppLocale.text('d_geshihua'),
                      cancel: AppLocale.text('cancel'),
                      confirm: AppLocale.text('confirm'),
                      message: AppLocale.text('lg_geshihuadata'),
                      onConfirm: () {

                        final toUpdate = {
                          "deviceId": _device?.deviceId,
                          "format": 1,
                        };
                        _deviceApi.format(toUpdate);

                        Navigator.pop(context);
                      },
                      onCancel: () {
                        Navigator.pop(context);
                      });
                },
              ),







            ],
          )),
    );
  }

}

























